package com.javalong.affairs.base.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtils {
    private static SimpleDateFormat sdf;
    private static SimpleDateFormat sdf2;
    private static SimpleDateFormat sdf3;
    private static SimpleDateFormat sdf4;
    static {
        sdf = new SimpleDateFormat("MM-dd");
        sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf4 = new SimpleDateFormat("MM-dd HH:mm");
    }

    public static String getFormat4Time(long time) {
        return sdf4.format(new Date(time * 1000));
    }

    public static String getFormatTime(long time) {
        return sdf.format(new Date(time * 1000));
    }

    public static String getFormatTime(String time) {
        return sdf.format(new Date(Long.parseLong(time) * 1000));
    }

    public static String getFormatTime2(long time) {
        return sdf2.format(new Date(time * 1000));
    }

    public static String getFormatTime2(String time) {
        return sdf2.format(new Date(Long.parseLong(time) * 1000));
    }


    public static Long getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime().getTime();
    }

    public static Long getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime().getTime();
    }

    public static String getTimeStr(long time) {
        time *= 1000;
        return sdf3.format(new Date(time));
    }
}
